<?php
ob_start();
session_start();
require("../conn.php");    
		 $vi_name=($_POST['vi_name']);
		 $en_name=($_POST['en_name']);
		 $URL=  $_POST['link_url'];
		 $order=$_POST['order'];
		 
		 if($_SESSION['Permit']==1)
		 {
			if($_POST['menus']=='menu')
			{
			 $parent_id=0;
			 $sid=0;
			}
			else if($_POST['menus']=='article') 
			{
			 $parent_id=$_POST['section_id'];
			 $sid=-1;
			}
			 else 
			 { 
               $parent_id=$_POST['parent_id'];
			   $sid=$_POST['sid'];
			 }
				
		 }
		 else
		 {
			 $parent_id=$_POST['section_id'];
			 $sid=-1;
 
		  }
		$sql=sprintf("insert into tblmenu (URl,vi_name,en_name,tblmenu.order,parent_id,section_id)value('%s','%s','%s','%s','%s','%s')", $URL,$vi_name,$en_name,$order,$parent_id,$sid);
			$kq=mysql_query($sql)or die(mysql_error());
	 
	
	
			if(!$kq)
			{
				?>
				<script language="javascript">
				alert("Tạo menu không thành công!");
			
				</script>
				<?php
					header("Location:../menua");
			}
			else
			{
				?>
				<script language="javascript">
				alert("Tạo menu thành công!");
			
				</script>
				<?php
			   
				header("Location:../menulist");
				
			}

		

?>
